package com.pic.mgt.syushin.action.shell;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;

import com.pic.mgt.syushin.action.SyushinBucketResendAction;
import com.pic.mgt.telnetd.AbstractCommandPerformer;

public class SyushinBucketResendCommandPerformer extends
		AbstractCommandPerformer {
	
	private final String commandName = "rsdbkt";
	private final String commandDescritpion = "resend a bucket file.";
	
	private SyushinBucketResendAction  syushinBucketResendAction;

	@Override
	protected void addOption(Options options) {
		options.addOption("bn", true, "assign bucket file name. (required)");
	}

	@Override
	protected String doCommandPerform(CommandLine commandLine) {
		if (!commandLine.hasOption("bn")) {
			return
			super.getReplyMessageWithReplyCode(
					"did not provide bucket file name.",
					this.COMMAND_PERFORM_FAILED_CODE);
		}
		
		// -------------------------------------------
		
		boolean isResendSuccessful =
				this.syushinBucketResendAction.resendBucket(commandLine.getOptionValue("bn"));
		
		if (isResendSuccessful) {
			return super.getCommandPerformFinishMsg();
		}
		else {
			return super.getCommandPerformFailedMsg();
		}
	}

	@Override
	public String getCommandDescription() {
		return this.commandDescritpion;
	}

	@Override
	public String getCommandName() {
		return this.commandName;
	}
	
	// --- getter and setter ---

	public void setSyushinBucketResendAction(
			SyushinBucketResendAction syushinBucketResendAction) {
		this.syushinBucketResendAction = syushinBucketResendAction;
	}

}
